package com.cqu.hhx.driver.controller;

import com.cqu.hhx.driver.entity.forWeb.AddMoney;
import com.cqu.hhx.driver.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author DJ
 * @create 2020-05-28 15:13
 */
@RestController
public class MoneyController {
    @Autowired
    private OrderService orderService;

    /**
     * 乘客充值账户
     * @param addMoney
     * @return 状态码： 0:成功 1:失败   账户余额
     */
    @RequestMapping(value = "/customer/add/money/",method = RequestMethod.POST)
    public Map<String,Object> addCustomerAccount(@RequestBody AddMoney addMoney){
        Map<String,Object> map=new HashMap<>();
        if(addMoney.getMoney()>0) {
            Float money = orderService.updateCustomerMoney(addMoney.getCustomerId(), addMoney.getMoney(), true);
            map.put("status",0);
            map.put("money",money);
        }else{
            map.put("status",1);
        }
        return map;
    }

}
